package com.cloud.code.牛客网;

import java.util.HashMap;
import java.util.Map;

public class Test73 {

    public static void main(String[] args) {
        twoSum(new int[]{3, 2, 4}, 6);
    }

    public static int[] twoSum(int[] numbers, int target) {

        Map<Integer, Integer> map = new HashMap<>();

        for (int i = 0; i < numbers.length; i++) {
            int tem = target - numbers[i];
            Integer integer = map.get(tem);
            if (integer != null) {
                if (i > integer) {
                    return new int[]{integer+1, i+1};
                } else {
                    return new int[]{i+1, integer+1};
                }
            }else {
                map.put(numbers[i],i);
            }
        }
        return null;
    }
}
